//
//  MainViewController.swift
//  sinaWb
//
//  Created by pAcio on 15/12/15.
//  Copyright © 2015年 pAcio. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    //  变成必选属性
       let mainTabBar = MainTabBar()
    
       @objc private func composeBtnDidClick() {
        print(__FUNCTION__)
    
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents:.TouchUpInside )
        
        
        //TabBar是只读属性 不能够直接进行设置 可以使用KVC在运行时 间接赋值(改变身份)
        
        setValue(mainTabBar, forKey: "tabBar")
        //添加子视图控制器
        addChildViewControllers()
    }
    
       private func addChildViewControllers() {
        
       
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    private func addChildViewController(vc: UIViewController,title: String,imageName: String){
      
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image =  UIImage(named:imageName )
//        vc.tabBarItem.selectedImage = UIImage(named: imageName+"_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //在swift中self可以忽略
        addChildViewController(nav)
        
    }
    
}
